<template>
    <div id="top-bar">
        <div class="top-bar">
			<h4>欢迎访问雷迪奥研发中心</h4>
            <div class="control" v-if="is_login">
                <span class="">欢迎登录</span>
                <span style="padding: 0 12px;"> | </span>
                <el-dropdown @command="handleCommand">
                    <span class="el-dropdown-link">
                        <span class="user-name">{{ userName }}<span class="user-box el-icon-caret-bottom"></span></span>
                    </span>
                    <el-dropdown-menu slot="dropdown">
                        <el-dropdown-item command="0">修改密码</el-dropdown-item>
                        <el-dropdown-item command="1">退出登录</el-dropdown-item>
                    </el-dropdown-menu>
                </el-dropdown>
            </div>
            <div class="control" v-else>
                <span class="register">注册</span>
                <router-link class="login" tag="span" to="/login">登录</router-link>
            </div>
		</div>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                is_login: false,
                userName: ''
            }
        },
        mounted() {
            this.getUser()
        },
        methods: {
            handleCommand(command){
                // console.log(command)
                if(command == '1'){
                    sessionStorage.setItem('sessionId', '');
                    this.$router.push("/login");
                }else{
                    this.$router.push("/changePwd");
                }
            },
            getUser() {
                // console.log(sessionStorage.getItem('userName'))
                if(!sessionStorage.getItem('userName') || sessionStorage.getItem('userName') == '') {
                    this.is_login = false
                } else {
                    this.is_login = true
                    this.userName = sessionStorage.getItem('userName')
                }
            }
        }
    }
</script>

<style scoped>
#top-bar {
    background:rgba(245,245,245,1);
}
.top-bar {
	height: 40px;
	width: 1200px;
	margin: 0 auto;
	display: flex;
	justify-content: space-between;
}
h4 {
	font-size: 14px;
	color: rgba(17,17,17,1);
    line-height: 40px;
    font-weight: 400;
    cursor: pointer;
}
.control {
    font-size: 14px;
	color: rgba(17,17,17,1);
    line-height: 40px;
    font-weight: 400;
}
.register {
    display: inline-block;
    width:60px;
    height:26px;
    line-height: 26px;
    text-align: center;
    color: #ffffff;
    background:rgba(195,24,31,1);
    border-radius:13px;
    margin-right: 20px;
    vertical-align: middle;
    cursor: pointer;
}
.login {
    cursor: pointer;
}
.user-name {
    cursor: pointer;
}
.user-box {
    font-size: 20px;
    vertical-align: middle;
}
</style>